﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NXDO.WebAPI.Controllers;
using System;
using System.Collections.Generic;
using TDM.DbData.DataEntity;

namespace TDM.WebSvr.Controllers.Project
{
    [AllowAnonymous]
    public class TestProjectController : ApiDbEntityController<TestProject, long>
    {

        protected override string GetPkName()
        {
            return "PrjID";
        }

        protected override string GetTableName()
        {
            return "TestProject";
        }


        public override TestProject Post([FromBody] TestProject data)
        {
            var user = HttpContext.User as NXDO.Data.Security.Principal.MemberPrincipal;
            long uid = Convert.ToInt64(user?.MemberId);
            if (uid == 0) throw new Exception("未获得登录信息");
            data.CreateTime = DateTime.Now;
            data.CreateUID = uid;
            return base.Post(data);
        }

        public override List<TestProject> PostCollection([FromBody] List<TestProject> datas)
        {
            var user = HttpContext.User as NXDO.Data.Security.Principal.MemberPrincipal;
            long uid = Convert.ToInt64(user?.MemberId);
            if (uid == 0) throw new Exception("未获得登录信息");
            datas.ForEach(data =>
            {
                data.CreateTime = DateTime.Now;
                data.CreateUID = uid;
            });
            return base.PostCollection(datas);
        }
        public override bool Delete(long pkValue)
        {
            return WebBiz.Project.TestProjectHelper.DeleteTestProject(pkValue);
        }

        public override List<bool> DeleteCollection([FromBody] List<long> pkValues)
        {
            return WebBiz.Project.TestProjectHelper.DeleteTestProject(pkValues);
        }

        internal static object GetPrjByResID(object prjID)
        {
            throw new NotImplementedException();
        }
    }
}
